package algo_annotations.ihm;

import algo_annotations.data.Data_a;
import algo_annotations.heuristique.TraitementSousGroupe;
import algo_annotations.ihm.couche.CoucheAnno_BB;
import algo_annotations.ihm.couche.CoucheAnno_LIEN;
import algo_annotations.ihm.couche.CoucheAnno_TXT;
import algo_annotations.ihm.couche.CoucheSite_rectMax;
import commons.data.I_Data;
import commons.data.I_Data.DataType;
import commons.ihm.A_PanelTOC;
import commons.ihm.A_PanelCartoTocTools;
import commons.drawing.couche.A_Couche;
import commons.ihm.ParametresAffichageCarto.TypeAffichage;
import commons.drawing.couche.CoucheBasic;
import commons.drawing.couche.I_Couche;
import java.util.ArrayList;
import javax.swing.DefaultListModel;

public class PanelTOC_a extends A_PanelTOC {

	// C'est le PanelCartoTocTools pere qui renseigne cette donnée, qui contient toutes les couches
	private Data_a data;
	
	// Différentes couches de la TOC
	public A_Couche coucheAnnosTXT;
	public A_Couche coucheAnnoLien;
	public A_Couche coucheAnnosBB;
	public A_Couche coucheSite;
	public A_Couche coucheSegment_optim;
	public A_Couche coucheSegment_noOptim;
	public A_Couche coucheSite_RectMax;

	private A_Couche coucheZone;


	private ArrayList<I_Couche> vAllCouche;

    public PanelTOC_a(A_PanelCartoTocTools panel_Pere) {
		super(panel_Pere);
        initComponents();

		// On sélectionne par défaut le mode d'affichage Carto
		panel_Pere.setTypeAffichage(TypeAffichage.PAPIER);
    }

	@Override
	public void setData(I_Data dataToDisplay) {
		this.data = (Data_a)dataToDisplay;

		// Construction des couches basées sur le Data
		coucheAnnosTXT       = new CoucheAnno_TXT(data);
		coucheAnnosBB        = new CoucheAnno_BB(data);
		coucheAnnoLien       = new CoucheAnno_LIEN(data);
		coucheSite           = new CoucheBasic("Couche des sites", DataType.SITE_A, data);
		coucheSegment_optim  = new CoucheBasic("Couche des segments optimisés ", DataType.SEGMENT_OPTIM_A, data);
		coucheSegment_noOptim= new CoucheBasic("Couche des segments non optimisés", DataType.SEGMENT_NOOPTIM_A, data);
		coucheSite_RectMax   = new CoucheSite_rectMax(data);

		coucheZone           = new CoucheBasic("Zones encarts", DataType.ZONE, data);


		vAllCouche = new ArrayList<I_Couche>();
		vAllCouche.add(coucheAnnosTXT);
		vAllCouche.add(coucheAnnosBB);
		vAllCouche.add(coucheAnnoLien);
		vAllCouche.add(coucheSite);
		vAllCouche.add(coucheSegment_optim);
		vAllCouche.add(coucheSegment_noOptim);
		vAllCouche.add(coucheSite_RectMax);
		vAllCouche.add(coucheZone);
	}

	// Remplissage de la liste des sousgroupe du traitement
	public void showTraitements (ArrayList<TraitementSousGroupe> vTrt_pass1, ArrayList<TraitementSousGroupe> vTrt_pass2) {
		DefaultListModel listModel = new DefaultListModel();
		for (TraitementSousGroupe trt : vTrt_pass1)
			listModel.addElement(trt);
		if (vTrt_pass2 != null) {
			for (TraitementSousGroupe trt : vTrt_pass2)
				listModel.addElement(trt);
		}
		list_Traitements.setModel(listModel);
	}

	// utile pour sélectionner le traitement pass2 unique généré en mode interactif
	//  afin de faciliter le lancement de l'algo pour ce Traitement
	public void selectLastTraitement() {
		list_Traitements.setSelectedIndex(list_Traitements.getModel().getSize()-1);
	}

	// Renvoie le traitement actuellement sélectionné dans la liste
	public TraitementSousGroupe getSelectedTraitement() {
		return (TraitementSousGroupe) list_Traitements.getSelectedValue();
	}

	@Override
	public ArrayList<I_Couche> getAllCouches() {
		return vAllCouche;
	}

	@Override
	public ArrayList<I_Couche> getVisibleCouches() {
		ArrayList<I_Couche> vCouche = new ArrayList<I_Couche>();
		if (data == null) return vCouche;

		// Pour les anno, on est toujours en mode Papier
		panel_Pere.setTypeAffichage(TypeAffichage.PAPIER);

			if (cb_Zone.isSelected())
				vCouche.add (coucheZone);
			if (cb_Papier_SiteRectMax.isSelected())
				vCouche.add(coucheSite_RectMax);
			if (cb_Papier_SegmentOptim.isSelected())
				vCouche.add(coucheSegment_optim);
			if (cb_Papier_SegmentNoOptim.isSelected())
				vCouche.add(coucheSegment_noOptim);
			if (cb_Papier_Sites.isSelected())
				vCouche.add(coucheSite);
			if (cb_Papier_LienAnnosite.isSelected())
				vCouche.add(coucheAnnoLien);
			if (cb_Papier_RectAnno.isSelected())
				vCouche.add(coucheAnnosBB);
			if (cb_Papier_Annotations.isSelected())
				vCouche.add(coucheAnnosTXT);

		return vCouche;
	}

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cb_Zone = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        cb_Papier_SiteRectMax = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        cb_Papier_SegmentNoOptim = new javax.swing.JCheckBox();
        cb_Papier_RectAnno = new javax.swing.JCheckBox();
        cb_Papier_LienAnnosite = new javax.swing.JCheckBox();
        cb_Papier_Sites = new javax.swing.JCheckBox();
        cb_Papier_SegmentOptim = new javax.swing.JCheckBox();
        cb_Papier_Annotations = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        list_Traitements = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();

        cb_Zone.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Zone.setSelected(true);
        cb_Zone.setText("Zones généralisation");
        cb_Zone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_ZoneActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel2.setText("Pour info :");

        cb_Papier_SiteRectMax.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_SiteRectMax.setText("Site_rectMax");
        cb_Papier_SiteRectMax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_SiteRectMaxActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 11));
        jLabel1.setText("Objets à éviter :");

        cb_Papier_SegmentNoOptim.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_SegmentNoOptim.setText("Seg (no optim)");
        cb_Papier_SegmentNoOptim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_SegmentNoOptimActionPerformed(evt);
            }
        });

        cb_Papier_RectAnno.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_RectAnno.setText("Rect Anno");
        cb_Papier_RectAnno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_RectAnnoActionPerformed(evt);
            }
        });

        cb_Papier_LienAnnosite.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_LienAnnosite.setText("Lien Anno-Site");
        cb_Papier_LienAnnosite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_LienAnnositeActionPerformed(evt);
            }
        });

        cb_Papier_Sites.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_Sites.setSelected(true);
        cb_Papier_Sites.setText("Sites");
        cb_Papier_Sites.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_SitesActionPerformed(evt);
            }
        });

        cb_Papier_SegmentOptim.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_SegmentOptim.setSelected(true);
        cb_Papier_SegmentOptim.setText("Segments (optim)");
        cb_Papier_SegmentOptim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_SegmentOptimActionPerformed(evt);
            }
        });

        cb_Papier_Annotations.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        cb_Papier_Annotations.setSelected(true);
        cb_Papier_Annotations.setText("Annotation");
        cb_Papier_Annotations.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_Papier_AnnotationsActionPerformed(evt);
            }
        });

        list_Traitements.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        list_Traitements.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list_Traitements.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list_TraitementsValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(list_Traitements);

        jLabel3.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jLabel3.setText("Liste traitements :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cb_Papier_SiteRectMax)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cb_Papier_SegmentNoOptim)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cb_Papier_Annotations)
                            .addComponent(cb_Papier_LienAnnosite)
                            .addComponent(cb_Papier_Sites))
                        .addGap(40, 40, 40))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cb_Zone)
                        .addContainerGap(8, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cb_Papier_SegmentOptim)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cb_Papier_RectAnno)
                        .addContainerGap(62, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap(41, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(cb_Papier_Annotations)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_LienAnnosite)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_Sites, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Zone)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_SegmentOptim)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_SegmentNoOptim)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_RectAnno)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_Papier_SiteRectMax)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

	private void cb_Papier_AnnotationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_AnnotationsActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_AnnotationsActionPerformed

	private void cb_Papier_SitesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_SitesActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_SitesActionPerformed

	private void cb_Papier_SegmentOptimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_SegmentOptimActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_SegmentOptimActionPerformed

	private void cb_Papier_LienAnnositeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_LienAnnositeActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_LienAnnositeActionPerformed

	private void cb_Papier_RectAnnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_RectAnnoActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_RectAnnoActionPerformed

	private void cb_Papier_SegmentNoOptimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_SegmentNoOptimActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_SegmentNoOptimActionPerformed

	private void cb_Papier_SiteRectMaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_Papier_SiteRectMaxActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_Papier_SiteRectMaxActionPerformed

	private void cb_ZoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_ZoneActionPerformed
		changeInSelectedCouche();
	}//GEN-LAST:event_cb_ZoneActionPerformed

	private void list_TraitementsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list_TraitementsValueChanged
		if (!list_Traitements.getValueIsAdjusting()) {
			TraitementSousGroupe trt = getSelectedTraitement();
			if (trt==null) return;
			
			list_Traitements.setToolTipText(trt.toString());

			// on demande au PanelCartoTocTools pere de selectionner les annos correspondant au sous-groupe
			panel_Pere.selectFromListObject((ArrayList) trt.sgs.getSites());
		}
	}//GEN-LAST:event_list_TraitementsValueChanged



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cb_Papier_Annotations;
    private javax.swing.JCheckBox cb_Papier_LienAnnosite;
    private javax.swing.JCheckBox cb_Papier_RectAnno;
    private javax.swing.JCheckBox cb_Papier_SegmentNoOptim;
    private javax.swing.JCheckBox cb_Papier_SegmentOptim;
    private javax.swing.JCheckBox cb_Papier_SiteRectMax;
    private javax.swing.JCheckBox cb_Papier_Sites;
    private javax.swing.JCheckBox cb_Zone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList list_Traitements;
    // End of variables declaration//GEN-END:variables


}
